<?php

namespace App\Services\Admin;

use App\Models\Area;
use App\Models\Store as StoreModel;

class Store extends Base
{
    public static function where_lists()
    {
        return (new StoreModel)->pluck('store_name', 'id');
    }

    public static function lists()
    {
        $input = request()->all();

        $where = [];

        if (!empty($input['sear_value'])) $where[] = ['store_name', 'like', '%' . $input['sear_value'] . '%'];

        return (new StoreModel)->where($where)->orderBy('id', 'desc')->paginate(15);
    }

    //查詢省
    public static function area($parent_id = 0)
    {
        return (new Area())->where('parent_id', $parent_id)->pluck('name','id');
    }

    public static function info($id)
    {
        return (new StoreModel)->where('id', $id)->first();
    }

    public static function add($param = [])
    {
        return (new StoreModel)->insert($param);
    }

    public static function edit($id , $param=[])
    {
        return (new StoreModel)->where('id',$id)->update($param);
    }
}
